package edu.hnzj.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sun.org.apache.bcel.internal.generic.RETURN;

import edu.hnzj.dao.UserDao;
import edu.hnzj.entity.User;
import edu.hnzj.util.JsonResult;

@Service("userService")
public class UserServiceImp implements UserService {

	@Resource
	private UserDao userDao;
	public JsonResult<User> checkLogin(String username, String password) {
		//接收结果数据
		JsonResult<User> result = new JsonResult<User>();
		//根据用户参数查询用户信息
		User user = userDao.findByName(username);
		
		if (user == null) {
			result.setStatus(1);
			result.setMsg("账号不存在");
			return result;
		}
		if (!user.getPassword().equals(password)) {
			result.setStatus(2);
			result.setMsg("密码错误");
			return result;
		}
		
		result.setStatus(0);
		result.setData(user);
		return result;
	}
	public JsonResult<Object> addUser(String name, String password) {
		JsonResult<Object> result = new JsonResult<Object>();
		User user=new User();
		user.setName(name);
		user.setPassword(password);
		userDao.save(user);
		result.setStatus(0);
		result.setMsg("添加成功");
		return result;
	}
	

}
